const array = [10, 20, 30, 40, 50];

// for (const element of array) {
//     console.log(element); // 依次打印 10, 20, 30, 40, 50
// }

// let object = {
//     name: 'tom',
//     age: 18,
//     sex: 'female'
// }

// for (const key in object) {
//     if (Object.prototype.hasOwnProperty.call(object, key)) {
//         const element = object[key];
//         console.log(element)
//     }
// }
// let index = 3

// array.forEach((element, index) => {
//     console.log(index)
//     console.log(element)
// });


// let newarray = array.map(Number => Number * Number)
// console.log(newarray)


// const number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

// for (const num of number) {
//     if (num % 2 !== 0) {
//         console.log(num)
//     }
// }

// const phrases = ['hello world', 'javascript is fun', 'openai gpt', 'coding is great'];

// for (const phrase of phrases) {
//     if (phrase.includes('is')) {
//         console.log(phrase)
//     }
// }

// const mixedNumbers = [-3, 5, -1, 8, -2, 7]
// let sum = 0
// for (const num of mixedNumbers) {
//     if (num > 0) {
//         sum += num
//     }
// }
// console.log(`Total sum of positive numbers: ${sum}`)

// const person = {
//     name: 'Alice',
//     age: 25,
//     city: 'Wonderland',
//     occupation: 'Engineer'
// }

// for (const key in person) {
//     if (typeof person[key] === 'string') {
//         console.log(person[key])
//     }
// }

// const data = {
//     a: 10,
//     b: 20,
//     c: 'thirty',
//     d: 40,
//     e: 'fifty'
// }

// let sum = 0
// for (const key in data) {
//     if (typeof data[key] === 'number') {
//         sum += data[key]
//     }
// }
// console.log(`Total sum of numeric values: ${sum}`)

// const inventory = {
//     apples: 5,
//     oranges: 0,
//     bananas: 8,
//     grapes: 2,
//     cherries: 0
// }
// for (const key in inventory) {
//     if (inventory[key] === 0) {
//         console.log(`${key}: ${inventory[key]}`)
//     }
// }

// const numbers = [-3, 5, -1, 8, -2, 7]
// let sum = 0
// let count = 0
// numbers.forEach(num => {
//     if (num > 0) {
//         sum += num
//         count++
//     }
// })

// const average = sum / count
// console.log(`Average of positive numbers: ${average}`)

// const words = ['apple', 'banana', 'cherry', 'date', 'fig', 'grape']
// const minLength = 5
// words.forEach(word => {
//     if (word.length > minLength) {
//         console.log(word)
//     }
// })

// const numbers = [-3, 5, -1, 8, -2, 7]

// const positiveNumbers = numbers.map(num => num < 0 ? -num : num)

// console.log(positiveNumbers)

const people = [
    { name: 'Alice', age: 25 },
    { name: 'Bob', age: 30 },
    { name: 'Charlie', age: 35 }
]

const uppercasedNames = people.map(person =>
    person.name.length > 3 ? { ...person, name: person.name.toUpperCase() } : person
)
console.log(uppercasedNames)

const numbers = [1, 2, 3, 4, 5, 110, 89, 110, 213];

const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 10);
console.log(sum)

let s = numbers.find(item => item = 110)
console.log(s)

let arr = ['yangyuanzhang', 'aifangdian', 'hajimi', 'koujiubai', 'yaohuiqu', 'jiewangyin']

let a = (array, str) => {
    for (const element of array) {
        if (element.includes(str)) {
            console.log(element);
        }
    }
}

a(arr, 'zh')

function b(array, str) {
    let farr = []
    for (const element of array) {
        if (element.includes(str)) {
            // console.log(element);
            // console.log('+============================')
            farr.push(element)
        }
    }
    return farr
}
let newarr = b(arr, 'ha')


console.log(newarr[0]);
